//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================


using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;
using System.Threading;
using Microsoft.Practices.EnterpriseLibrary.Caching;


namespace Shp.Runtime.Sitka.ServiceAgent.Tests
{
    /// <summary>
    /// Summary description for RepositoryCacheFixture
    /// </summary>
    [TestClass]
    public class CacheFixture
    {
        public CacheFixture()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion


        [TestMethod]
        public void ShouldRetrieveTwoCacheManagerInstancesFromEntlibCacheFactoryAndBeTheSame()
        {
            CacheManager firstManager = CacheFactory.GetCacheManager();

            CacheManager secondManager = CacheFactory.GetCacheManager();

            Assert.AreEqual(firstManager.GetHashCode(), secondManager.GetHashCode());
        }

        [TestMethod]
        [ExpectedException(typeof(NullReferenceException))]
        public void ShouldDisposeCacheManagerInstanceThenGetAnotherOneFromEntlibCacheFactoryAndBeUnusable()
        {           
            CacheManager firstManager = CacheFactory.GetCacheManager();

            firstManager.Dispose();

            CacheManager secondManager = CacheFactory.GetCacheManager();

            secondManager.Add("SampleKey", "sampleValue");           
        }

       

       

    }
}
